<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../include/laypublic.jsp" %>
<%@ include file="../include/vueComponent.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <title>设备合同评审</title>
</head>
<style>
    .unit_img div {
        height: 41px;
    }
</style>
<link rel="stylesheet" href="${ctx}/resources/vue-element-lib/detail.css">
<body>
<div id="app">
    <div class="layui-tab layui-tab-brief" lay-filter="xqxx-tab-all">
        <ul class="layui-tab-title">
            <li id="tbglId" class="layui-this" lay-id="0">设备合同评审</li>
            <li id="zgysId" lay-id="1">历史审批信息</li>
        </ul>
        <div class="layui-tab-right">
            <%--            <c:if test="${isAuditFlag eq '1'}">--%>
            <template v-if="layId==0">
                <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" @click="save(0)">保存
                </button>
                <button type="button" class="layui-btn layui-btn-radius" @click="save(1)">提交</button>
            </template>
            <%--            </c:if>--%>
            <c:if test="${auditTabFlag eq '1'}">
                <button type="button" class="layui-btn layui-btn-primary layui-btn-radius" @click="audit(0)">
                    不同意
                </button>
                <button type="button" class="layui-btn layui-btn-radius" @click="audit(1)">同意</button>
            </c:if>
        </div>
        <div class="layui-tab-content" style="height: 100px;">
            <div class="layui-tab-item layui-show">
                <div class="container">
                    <el-form ref="formRef" label-width="180px" label-suffix="："
                             label-position="left">

                        <div class="title">
                            <h3>项目基础信息</h3>
                        </div>
                        <el-row>
                            <x-col>
                                <el-form-item label="项目名称">
                                    <span>{{basic.proName}}</span>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="项目编码">
                                    <span>{{basic.proCode}}</span>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <el-row>
                            <x-col>
                                <el-form-item label="申请公司">
                                    <span>{{basic.compName}}</span>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="申请部门">
                                    <span>{{basic.deptName}}</span>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <el-row>
                            <x-col>
                                <el-form-item label="申请人">
                                    <span>{{basic.staffName}}</span>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="区域公司">
                                    <span>{{basic.compName}}</span>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <el-row>
                            <x-col>
                                <el-form-item label="项目公司">
                                    <span>{{basic.compName}}</span>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="实施机构">
                                    <span>{{basic.compName}}</span>
                                </el-form-item>
                            </x-col>
                        </el-row>

                        <el-row>
                            <x-col>
                                <el-form-item label="项目负责人">
                                    <x-input name="项目负责人" v-model="basic.projectLeader"></x-input>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="项目地址">
                                    <span>{{basic.cityName}}</span>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <div class="title">
                            <h3>合同评审信息</h3>
                        </div>
                        <el-row>
                            <x-col>
                                <el-form-item label="设备合同名称">
                                    <x-input name="设备合同名称" v-model="info.contractName"></x-input>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="公司名称">
                                    <el-select v-model="info.sgCoopId" placeholder="请选择公司名称" filterable
                                               style="width: 100%;">
                                        <el-option v-for="item in companyList" :key="item.SGUID" :label="item.COOP_NAME"
                                                   :value="item.SGUID">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <el-row>
                            <x-col>
                                <el-form-item label="合同签订日期">
                                    <el-date-picker type="date" placeholder="请选择合同签订日期"
                                                    value-format="yyyy-MM-dd" v-model="info.signDate"
                                                    style="width: 100%"></el-date-picker>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="设备合同编码">
                                    <x-input name="设备合同编码" v-model="info.deviceCotCode"></x-input>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <div class="title">
                            <h3>合价款信息</h3>
                        </div>
                        <div class="unit">
                            <div class="unit_add">
                                <button class="layui-btn layuiadmin-btn-admin" type="button" data-type="add"
                                        @click="add()">
                                    添加清单
                                </button>
                            </div>
                            <div class="unit_center">
                                <div class="unit_img">
                                    <div class="item" v-for="(item,index) in expenseInvoiceList" :key="index"
                                         v-if="expenseInvoiceList.length>1">
                                        <img src="${ctx}/resources/images/del.png" alt=""
                                             @click="del(index)">
                                    </div>
                                </div>
                                <el-table :data="expenseInvoiceList" style="width: 100%" border>
                                    <el-table-column label="分部分项清单名称" align="center">
                                        <template slot-scope="scope">
                                            <x-input name="分部分项清单名称" v-model="scope.row.namesList"></x-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="计量单位" align="center">
                                        <template slot-scope="scope">
                                            <x-input name="计量单位" v-model="scope.row.unitMeasurement"></x-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="合同数量" align="center">
                                        <template slot-scope="scope">
                                            <x-input name="合同数量" v-model="scope.row.contractQuantity" type="number"
                                                     min="0" @input="sum"></x-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column label="合同单价" align="center">
                                        <template slot-scope="scope">
                                            <x-input name="合同单价" v-model="scope.row.contractPrice" type="number"
                                                     min="0" @input="sum"></x-input>
                                        </template>
                                    </el-table-column>
                                    <el-table-column prop="summation" label="合计" align="center"></el-table-column>
                                </el-table>
                            </div>
                        </div>
                        <div class="title">
                            <h3>合同信息</h3>
                        </div>
                        <el-row>
                            <x-col>
                                <el-form-item label="合同工期(年)">
                                    <x-input name="合同工期" v-model="info.contractYearTime" type="number"
                                             min="0"></x-input>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="合同工期(天)">
                                    <span>{{info.contractYearTime?info.contractYearTime*365:0}}</span>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <el-row>
                            <x-col>
                                <el-form-item label="合同开工日期">
                                    <el-date-picker type="date" placeholder="请选择合同开工日期"
                                                    value-format="yyyy-MM-dd" v-model="info.beginBuildDate"
                                                    style="width: 100%"></el-date-picker>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="合同竣工日期">
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <el-row>
                            <x-col>
                                <el-form-item label="实际开工日期">
                                    <el-date-picker type="date" placeholder="请选择实际开工日期"
                                                    value-format="yyyy-MM-dd" v-model="info.beginBuildDateAct"
                                                    style="width: 100%"></el-date-picker>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="调整后竣工日期">
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <el-row>
                            <x-col>
                                <el-form-item label="实际竣工日期">
                                    <el-date-picker type="date" placeholder="请选择实际竣工日期"
                                                    value-format="yyyy-MM-dd" v-model="info.endBuildDateAct"
                                                    style="width: 100%"></el-date-picker>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="预付款比例(%)">
                                    <x-input name="预付款比例" v-model="info.preChargeRate" type="number" min="0"></x-input>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <el-row>
                            <x-col>
                                <el-form-item label="月度付款比例(%)">
                                    <x-input name="月度付款比例" v-model="info.monthChargeRate" type="number"
                                             min="0"></x-input>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="年度付款比例(%)">
                                    <x-input name="年度付款比例" v-model="info.yearChargeRate" type="number"
                                             min="0"></x-input>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <el-row>
                            <x-col>
                                <el-form-item label="竣工验收付款比例(%)">
                                    <x-input name="竣工验收付款比例" v-model="info.endChargeRate" type="number"
                                             min="0"></x-input>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="结算后比例(%)">
                                    <x-input name="结算后比例" v-model="info.settChargeRate" type="number" min="0"></x-input>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <el-row>
                            <x-col>
                                <el-form-item label="质保金比例(%)">
                                    <x-input name="质保金比例" v-model="info.qaChargeRate" type="number" min="0"></x-input>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="居间费承担方">
                                    <el-select v-model="info.interFeeOrg" placeholder="请选择居间费承担方" filterable
                                               style="width: 100%;">
                                        <el-option v-for="item in list" :key="item.SGUID" :label="item.COMP_NAME"
                                                   :value="item.SGUID">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <el-row>
                            <x-col>
                                <el-form-item label="农民工保证金承担方">
                                    <el-select v-model="info.marginOrg" placeholder="请选择农民工保证金承担方" filterable
                                               style="width: 100%;">
                                        <el-option v-for="item in list" :key="item.SGUID" :label="item.COMP_NAME"
                                                   :value="item.SGUID">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </x-col>
                            <x-col position="right">
                                <el-form-item label="履约保函承担方">
                                    <el-select v-model="info.ensure" placeholder="请选择履约保函承担方" filterable
                                               style="width: 100%;">
                                        <el-option v-for="item in list" :key="item.SGUID" :label="item.COMP_NAME"
                                                   :value="item.SGUID">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </x-col>
                        </el-row>
                        <el-row>
                            <x-col position="full">
                                <el-form-item label="质量标准">
                                    <x-input type="textarea" :rows="4" name="质量标准" v-model="info.soqMemo"></x-input>
                                </el-form-item>
                            </x-col>
                        </el-row>

                        <div class="title">
                            <h3>项目附件信息</h3>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">Word版合同文本</label>
                            <div class="layui-input-block">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn" type="button" id="95-upload-more">上传
                                    </button>
                                    <div class="layui-upload-list" id="95-upload-more-list">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">PDF版合同文本</label>
                            <div class="layui-input-block">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn" type="button" id="96-upload-more">上传
                                    </button>
                                    <div class="layui-upload-list" id="96-upload-more-list">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">政府发函</label>
                            <div class="layui-input-block">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn" type="button" id="97-upload-more">上传
                                    </button>
                                    <div class="layui-upload-list" id="97-upload-more-list">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">其他附件</label>
                            <div class="layui-input-block">
                                <div class="layui-upload">
                                    <button type="button" class="layui-btn" type="button" id="98-upload-more">上传
                                    </button>
                                    <div class="layui-upload-list" id="98-upload-more-list">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </el-form>
                </div>
            </div>
            <%--<div class="layui-tab-item">
                <%@ include file="process/process-history.jsp" %>
            </div>--%>
        </div>
    </div>
</div>
<script src="${ctx}/resources/vue-element-lib/jquery.js"></script>
<script>
    // 封装上传文件
    let fileArr = [];

    var staticPath = '${fileHttpPre}';
    layui.config({
        base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'set', 'upload', 'table', 'transfer', 'laydate', 'element', 'layer'], function () {
        var $ = layui.$
            , upload = layui.upload
            , table = layui.table
            , element = layui.element
            , layer = layui.layer;

        //选项卡切换监听
        element.on('tab(xqxx-tab-all)', function (data) {
            var layId = $(this).attr('lay-id');
            vm.$data.layId = layId
            if (layId === "0") {

            } else if (layId === "1") {
                loadTable(layId);
            } else if (layId === "2") {

            }
        });

        function loadTable(layId) {
            // 表单
            table.render({
                elem: '#lay-lsspxx-create-manage'
                , url: basePath + '/historyProcess/list?proCode=${proCode}'
                , cols: [[
                    {
                        field: 'startTime', title: '发起时间', width: 145, width: 155, templet: function (d) {
                            return layui.util.toDateString(d.startTime, "yyyy-MM-dd HH:mm:ss");
                        }
                    }
                    , {field: 'startRealName', title: '发起人', width: 145}
                    , {field: 'proFlowType', title: '审批阶段', width: 145}
                    , {
                        field: 'dealTime', title: '审批日期', width: 155, templet: function (d) {
                            return layui.util.toDateString(d.dealTime, "yyyy-MM-dd HH:mm:ss");
                        }
                    }
                    , {field: 'dealName', title: '审批人', width: 160}
                    , {
                        field: 'state', title: '审批状态'
                    }
                    , {
                        title: '操作', width: 140, align: 'center', fixed: 'right', templet: function (d) {
                            var optStr = "";
                            optStr += '<a class="layui-btn layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-form"></i>查看</a>';
                            return optStr;
                        }
                    }
                ]]
                , page: true
                , limit: 10
            });

            // 监听操作列
            table.on('tool(lay-lsspxx-create-manage)', function (obj) {
                var data = obj.data;
                if (obj.event === 'view') {//查看
                    parent.layui.index.openTabsPage(basePath + '/historyProcess/toDetail?processId=' + data.processId, '历史流程信息 > 详情');
                }
            });
        }
        ;(function () {
            //定义构造函数
            var Upfile = function (ele, type, opt) {
                this.defaults = {
                    //elem:‘#uploadPic‘	//绑定元素
                    elem: $(ele)	//绑定元素
                    , url: basePath + '/contractInfo/uploadAtt/',
                    data: {
                        types: type
                    },
                    multiple: true,
                    accept: 'file',
                    acceptMime: 'application/zip,application/x-rar-compressed,image/jpeg,image/png,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/pdf',

                    method: 'post',
                    before: function (obj) { //obj参数包含的信息
                        layer.load(); //上传loading
                    },
                    done: function (res) {
                        //如果上传失败
                        if (res.code > 0) {
                            layer.closeAll('loading'); //关闭loading
                            return layer.msg(res.msg, {icon: 7});
                        }
                        //上传完毕
                        if (res.entity != null && res.entity.length > 0) {
                            fileArr.push(res.entity[0])
                            for (var i in res.entity) {
                                var contractInfo = res.entity[i];
                                var arr = contractInfo.split("|");
                                var imgSrc = "";
                                var suffix = arr[1].substring(arr[1].lastIndexOf(".") + 1, arr[1].length);
                                if (suffix == 'jpg' || suffix == 'png') {
                                    imgSrc = "${fileHttpPre}/" + arr[3];
                                } else {
                                    imgSrc = "${ctx}/resources/images/" + suffix + ".jpg";
                                }
                                $('#' + type + '-upload-more-list')
                                    .append('<div class="layui-upload-img-div" id="upload_img_' + arr[2] + '"><img src="' + imgSrc + '" title="'
                                        + arr[1] + '" class="layui-upload-img"><div class="mask"><a href="javascript:void(0)" onclick="showImg(\'' + "${fileHttpPre}"
                                        + arr[3] + '\');">查看</a><a href="javascript:void(0)" onclick="del(\''
                                        + arr[2] + '\')";>删除</a></div><p>' + arr[1] + '</p><input type="hidden" value="'
                                        + contractInfo + '" id="fileAtt_' + arr[2] + '" name="fileAtts" ></input></div> ');
                            }
                        }
                    },
                    allDone: function (obj) { //当文件全部被提交后，才触发
                        layer.closeAll('loading'); //关闭loading
                    },
                    error: function () {
                        layer.closeAll('loading'); //关闭loading
                        //上传失败
                        layer.msg("上传失败，请稍后再试~", {icon: 7});
                    }
                }
                this.options = $.extend({}, this.defaults, opt);
            };

            //定义方法
            Upfile.prototype = {
                init: function () {
                    var _this = this;
                    return layui.use('upload', function () {
                        var upload = layui.upload;

                        //执行实例
                        var uploadInst = upload.render(_this.options);
                    });
                }
            };

            //在插件中使用对象
            $.fn.upfile = function (options) {
                var upfile = new Upfile(this, options);
                return upfile.init();
            }
        })();
        //上传文件
        $('#95-upload-more').upfile(95);
        $('#96-upload-more').upfile(96);
        $('#97-upload-more').upfile(97);
        $('#98-upload-more').upfile(98);

    });

    //删除文件
    function del(index) {
        layui.$("#fileAtt_" + index).remove();
        layui.$("#upload_img_" + index).remove();
        fileArr.map((el, idx) => {
            if (el.split('|')[2] == index) {
                fileArr.splice(idx, 1)
            }
        })
    }

    //根据url查看文件
    function showImg(url) {
        var openWin = window.open(url, '', 'left=410,height=768, width=1024, top=200,  toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
    }

    /*核心*/
    var vm = new Vue({
        el: '#app',
        data() {
            return {
                layId: 0,
                list: [],
                expenseInvoiceList: [],//合价款信息列表
                basic: {},
                info: {},
                companyList: [],
            }
        },
        created() {
            this.id = "${id}"
            this.queryById();
            this.companyNameDropDownBox();
            this.projectCompanyBox();
        },


        mounted() {

        },
        methods: {
            projectCompanyBox() {
                zAjax('/deviceCot/projectCompanyBox', {}).then(res => {
                    this.list = res
                })
            },
            companyNameDropDownBox() {
                zAjax('/contractsReview/companyNameDropDownBox', {types: 5}).then(res => {
                    this.companyList = res
                })
            },
            queryById() {
                zAjax('/deviceCot/queryById', {id: this.id}).then(res => {
                    this.basic = res.basic;
                    this.info = res.deviceCot;
                    if (res.expenseInvoiceList && res.expenseInvoiceList.length > 0) this.expenseInvoiceList = res.expenseInvoiceList;
                    showFile(res.fileAtt)
                })
            },
            add() {
                let obj = {
                    namesList: '',// 分部分项清单名称
                    unitMeasurement: '',// 计量单位
                    contractQuantity: '',//合同数量
                    contractPrice: '',// 合同单价
                    summation: '',// 合计
                }
                this.expenseInvoiceList.push(obj);
            },
            del(index) {
                this.expenseInvoiceList.splice(index, 1);
            },
            sum() {
                this.expenseInvoiceList.map(el => {
                    if (el.contractQuantity && el.contractPrice) {
                        el.summation = Number(el.contractQuantity) * Number(el.contractPrice);
                        el.summation = el.summation.toFixed(2)
                    } else {
                        el.summation = 0
                    }
                })
            },
            error(text) {
                this.$message({
                    message: text,
                    type: 'warning'
                });
            },
            //保存
            save(type) {
                let obj = {
                    basic: this.basic,//项目基础信息
                    deviceCot: this.info,
                    expenseInvoiceList: this.expenseInvoiceList,
                    fileAtt: fileArr
                }
                obj.deviceCot.id = this.basic.id;
                obj.deviceCot.proCode = this.basic.proCode;

                let str = JSON.stringify(obj).replace(/\"/g, '\\"');
                zAjax('/deviceCot/save', {
                    bodyStr: str,
                    submitType: type + ''
                }).then(res => {
                    if (res.success) {
                        this.$message({
                            message: res.msg,
                            type: 'success'
                        });
                    } else {
                        this.$message.error(res.msg);
                    }
                })
            },
        }
    })
</script>
</body>
</html>

